import { socket } from "@kit.NetworkKit";
import { SSLSocket } from "./SSLSocket";
import { SocketFactory } from './SocketFactory';
import { X509TrustManager, X509TrustManagerSystem } from "./X509TrustManager";


export class SSLSocketFactory {
  // static final boolean DEBUG;
  ca: string[]
  cert: string
  key: string
  password: string
  tm: X509TrustManager
  constructor(ca?: string[], cert?: string, key?: string, password?: string, tm?: X509TrustManager) {
    this.ca = ca ?? []
    this.cert = cert ?? ''
    this.key = key ?? ''
    this.password = password ?? ''
    this.tm = tm ?? X509TrustManagerSystem.SYSTEM
  }

  createSocket(tcp?: socket.TCPSocket): SSLSocket{
    if (tcp) {
      return new SSLSocket(socket.constructTLSSocketInstance(tcp))
    }
    return new SSLSocket(socket.constructTLSSocketInstance())
  }

  equals(other: unknown): boolean {
    if (!(other instanceof SSLSocketFactory)) return false;
    return (
      this.ca === other.ca &&
        this.cert === other.cert &&
        this.key === other.key &&
        this.password === other.password &&
        this.tm === other.tm
    );
  }
}
